Socket
Socket
Sign inDemoInstall

del

Package Overview
Dependencies
24
Maintainers
1
Versions
27
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    del

Delete files and folders


Version published
Weekly downloads
14M
decreased by-0.88%
Maintainers
1
Install size
244 kB
Created
Weekly downloads
 

Package description

What is del?

The del npm package is a powerful tool for deleting files and directories in a Node.js environment. It uses globs to select files and is built on top of the rimraf package, providing a promise-based API that supports multiple files and globbing patterns.

What are del's main functionalities?

Delete files and directories

This feature allows you to delete files and directories using glob patterns. The example shows how to delete all JavaScript files in the 'temp' directory except 'temp/unicorn.js'.

const del = require('del');

del(['temp/*.js', '!temp/unicorn.js']).then(paths => {
    console.log('Deleted files and folders:\n', paths.join('\n'));
});

Dry run

This feature performs a dry run without actually deleting the files. It's useful for testing which files would be deleted.

const del = require('del');

del(['temp/*.js'], {dryRun: true}).then(paths => {
    console.log('Files and folders that would be deleted:\n', paths.join('\n'));
});

Force deletion

This feature allows you to delete files outside of the current working directory. Use with caution as it can potentially cause data loss.

const del = require('del');

del(['../temp/*.js'], {force: true}).then(paths => {
    console.log('Deleted files and folders:\n', paths.join('\n'));
});

Other packages similar to del

Readme

Source

del Build Status XO code style

Delete files and folders using globs

Similar to rimraf, but with a Promise API and support for multiple files and globbing. It also protects you against deleting the current working directory and above.


🐶

Support this project and improve your JavaScript skills with this great ES6 course by Wes Bos.
Try his free JavaScript 30 course for a taste of what to expect. You might also like his React and Sublime course.


Install

$ npm install --save del

Usage

const del = require('del');

del(['tmp/*.js', '!tmp/unicorn.js']).then(paths => {
	console.log('Deleted files and folders:\n', paths.join('\n'));
});

Beware

The glob pattern ** matches all children and the parent.

So this won't work:

del.sync(['public/assets/**', '!public/assets/goat.png']);

You have to explicitly ignore the parent directories too:

del.sync(['public/assets/**', '!public/assets', '!public/assets/goat.png']);

Suggestions on how to improve this welcome!

API

del(patterns, [options])

Returns a promise for an array of deleted paths.

del.sync(patterns, [options])

Returns an array of deleted paths.

patterns

Type: string Array

See supported minimatch patterns.

options

Type: Object

See the glob options.

force

Type: boolean
Default: false

Allow deleting the current working directory and outside.

dryRun

Type: boolean
Default: false

See what would be deleted.

const del = require('del');

del(['tmp/*.js'], {dryRun: true}).then(paths => {
	console.log('Files and folders that would be deleted:\n', paths.join('\n'));
});
concurrency

Type: number
Default: Infinity
Minimum: 1

Concurrency limit.

CLI

See del-cli for a CLI for this module and trash-cli for a safe version that is suitable for running by hand.

  • make-dir - Make a directory and its parents if needed
  • globby - User-friendly glob matching

License

MIT © Sindre Sorhus

Keywords

FAQs

Last updated on 09 Jun 2017

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc